<?php
/* @var $this SelisteController */
/* @var $model Seliste */
/* @var $form CActiveForm */

$cs = Yii::app()->getClientScript();
$cs->registerScript('form_message', "

$('#Destinataire_idseliste').multiselect({
	checkboxName: 'destinataires[]',
	enableFiltering:true,
	enableCaseInsensitiveFiltering: true,
	filterPlaceholder:'Rechercher un destinataire',
	maxHeight:400,
	nonSelectedText:'Choisir un (ou des) destinataire(s)',
	nSelectedText:' destinataires sélectionnés'
});

		
",CClientScript::POS_END );
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'newmail-form',
	'htmlOptions'=>array('class'=>'form-horizontal'),
	'enableAjaxValidation'=>false,
)); ?>

	<?php $labels = $model->attributeLabels();?>

	<?php echo $form->errorSummary(array($model,$dest),NULL,NULL,array("class"=>"alert alert-danger")); ?>
	
	<div class="form-group<?php if ($dest->getErrors('idseliste')) echo " has-error";?>">
	    <?php 
	    echo $form->labelEx($dest,'idseliste',array("class"=>"col-lg-2 control-label")); 
	    ?>
	    <div class="col-lg-10">
		    <?php 
		    if ($model->idmessage == NULL) {
			    $data = CHtml::listData(Seliste::model()->findAll(array('condition'=>'id<>'.Yii::app()->user->id.' AND hum=1','order'=>'pseudo asc')),'id','pseudo');
			    echo $form->dropDownList($dest,'idseliste',$data,array("class"=>"form-control multiselect","multiple"=>"multiple"));
		    } else {
				$seliste = Seliste::model()->findByPk($dest->idseliste);
				$data = array($seliste->id=>$seliste->pseudo);
				echo $form->dropDownList($dest,'idseliste',$data,array("class"=>"form-control"));
				echo $form->hiddenField($model,"idmessage");
			}
		    ?>
	    </div>
	</div>
	
	 <div class="form-group<?php if ($model->getErrors('sujet')) echo " has-error";?>">
     	<?php echo $form->labelEx($model,'sujet',array("class"=>"col-lg-2 control-label")); ?>
        <div class="col-lg-10"><?php echo $form->textField($model,'sujet',array("class"=>"form-control")); ?></div>
    </div>
    
    <div class="form-group<?php if ($model->getErrors('message')) echo " has-error";?>">
		<?php echo $form->labelEx($model,'message',array("class"=>"col-md-2 control-label")); ?>
		<div class="col-md-10">
			<?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50,'class'=>"form-control")); ?>
		</div>
	</div>

	<div class="form-group">
		<div class="col-lg-offset-2 col-lg-10">
			<?php echo CHtml::submitButton('Envoyer',array("class"=>"btn btn-primary")); ?>
			<?php
			if ($model->idmessage == NULL) { 
				echo CHtml::link("Annuler",array('seliste/mailbox'),array('class'=>"btn btn-sm btn-info"));
			} else {
				echo CHtml::link("Retour au message",array('seliste/mail',"id"=>$model->idmessage),array('class'=>"btn btn-sm btn-info"));
			}	
			?>
		</div>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->